"""
@File    :   router.py
@Time    :   2024/03/08 16:43:46
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   OAuth2客户端模式认证相关路由
"""

from typing import Annotated

from fastapi import APIRouter, Depends

from src.business.admin.system.oauth2.auth.client_credentials.dependencies.route_depend import (
    route_depend_client_credentials_create_double_token,
)
from src.business.admin.system.oauth2.token.schemas.out import (
    DoubleTokenCompleteOutSchema,
)
from src.utils.unified_response import SuccessApiJSONResponse

# 创建路由
router = APIRouter(
    prefix="/admin/system/oauth2/auth/client-credentials",
    tags=[
        "后台OAuth2客户端模式认证接口",
    ],
)


@router.post("/authiruze", summary="请求认证")
async def route_authiruze(
    double_token: Annotated[
        DoubleTokenCompleteOutSchema,
        Depends(route_depend_client_credentials_create_double_token),
    ],
):
    """OAuth2客户端模式请求认证, 返回双Token"""
    access_token, refresh_token = double_token.access_token, double_token.refresh_token
    data = {
        "access_token": access_token.access_token,
        "access_token_expiration_datetime": access_token.expiration_datetime,
        "refresh_token": refresh_token.refresh_token,
        "refresh_token_expiration_datetime": refresh_token.expiration_datetime,
        "token_type": access_token.token_type,
        "scopes": access_token.oauth2_scopes,
    }
    return SuccessApiJSONResponse(message="OAuth2客户端模式请求认证成功", data=data)
